using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace Triton.Bot.Profiles
{
	[XmlRoot("Switch")]
	[ProfileElementName("Switch")]
	public class SwitchTag : ProfileGroupElement
	{
		public class SwitchArgument
		{
			[CompilerGenerated]
			private string string_0;

			[CompilerGenerated]
			private List<ProfileElement> list_0;

			[XmlAttribute("Value")]
			public string Value
			{
				[CompilerGenerated]
				get
				{
					return string_0;
				}
				[CompilerGenerated]
				set
				{
					string_0 = value;
				}
			}

			public List<ProfileElement> Children
			{
				[CompilerGenerated]
				get
				{
					return list_0;
				}
				[CompilerGenerated]
				set
				{
					list_0 = value;
				}
			}
		}

		private string string_0;

		private Func<string> func_0;

		private SwitchArgument switchArgument_0;

		private bool bool_0;

		[CompilerGenerated]
		private List<SwitchArgument> list_1;

		public override string Name => "Switch";

		public override string Author => "Bossland GmbH";

		public override string Description => "";

		public override string Version => "1.0.0.0";

		[XmlAttribute("Condition")]
		public string ConditionString
		{
			get
			{
				return string_0;
			}
			set
			{
				if (value != string_0)
				{
					string_0 = value;
					func_0 = ProfileScripting.GetCondition<string>("str(" + value + ")");
				}
			}
		}

		[XmlIgnore]
		public string Condition => func_0();

		public override bool IsFinished => bool_0;

		[XmlElement("Arg")]
		public List<SwitchArgument> Arguments
		{
			[CompilerGenerated]
			get
			{
				return list_1;
			}
			[CompilerGenerated]
			set
			{
				list_1 = value;
			}
		}

		public override void Reset()
		{
			base.Reset();
			bool_0 = false;
		}

		private void method_0()
		{
			string condition = Condition;
			foreach (SwitchArgument argument in Arguments)
			{
				if (argument.Value == condition)
				{
					switchArgument_0 = argument;
					break;
				}
			}
			if (switchArgument_0 == null)
			{
				throw new Exception("Switch argument does not contain a matching value! Current condition: " + ConditionString + " => " + condition);
			}
		}

		public override async Task ProfileTagLogic()
		{
			method_0();
			foreach (ProfileElement child in switchArgument_0.Children)
			{
				child.Reset();
				await child.ProfileTagLogic();
			}
			bool_0 = true;
		}
	}
}
